package com.ddl.common.exception;


import com.ddl.common.enums.ErrorCode;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2018/4/18
 */
public class ExceptionUtil {
    /**
     * 获取 Exception
     * @param e
     * @return
     */
    public static ResultModel getMessageException(Exception e) {
        ResultModel resultModel = new ResultModel();
        if (e instanceof BusinessException) {
            BusinessException be = ((BusinessException)e);
            resultModel.setCode(be.getErrorCode().getCode());
            resultModel.setMsg(be.getErrorMsg());
        } else if(e.getClass()== IllegalArgumentException.class){
            resultModel.setCode(ErrorCode.BUSSINESS_ERROR_201.getCode());
            if(e.getMessage()==null){
                resultModel.setMsg(ErrorCode.BUSSINESS_ERROR_201.getMessage());
            }else {
                resultModel.setMsg(e.getMessage());
            }
        } else {
            resultModel.setCode(ErrorCode.BUSSINESS_ERROR_203.getCode());
            resultModel.setMsg(ErrorCode.BUSSINESS_ERROR_203.getMessage());
        }
        return resultModel;
    }
}
